package stationGUI;

import java.net.*;
import java.awt.Color;
import java.io.*;

public class MultiServerThread extends Thread {
  private Socket socket;
  private ServerNode node;

  public MultiServerThread(Socket socket, ServerNode node) {
    super("MultiServerThread");
    this.socket = socket;
    this.node = node;
  }

  public void run() { try {
    ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
    node.setOutStream(out);
    ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
    Color cin;
    
    //Protocol p = new Protocol();
    
    //node.setServerOut(out);
    out.writeObject(node.bean);

    while ((cin = (Color) in.readObject()) != null) {
      System.out.println("I got a color!: "+cin);
      node.setColor(cin);
    }
    out.close();
    in.close();
    socket.close();

	} catch (IOException e) {
	    System.err.println("IOException: "+e);
	    e.printStackTrace();
	} catch (ClassNotFoundException e) {
	    System.err.println("Class not found: "+e);
	    e.printStackTrace();
	} catch (Exception e) {
	    System.err.println("General exception: "+e);
  } }
}